#include <iostream>
const int N = 100500;
int p[N];
int n, m;

int find(int v){
	if (p[v] != v) p[v] = find(p[v]);
	return p[v];
}

int main(){

	char o;
	int a, b;
	std::cin >> n >> m;
	for (int i = 1; i<= n; i++) p[i] = i;
	while (m--) {
		std::cin >> o >> a >> b;
		if (o == 'M'){
			if (find(a)!=find(b)){
				p[find(a)] = find(b);
			}
		}else {
			if (find(a) == find(b)){
				std::cout << "Yes";
			}else {
				std::cout << "No";
			}
			std::cout << std::endl;
		}
	}
}
